window.onload = function () { console.log("scroll js loaded"); /*29052024-2204 changes start*/ /*if (window.location.hash) { // Extract the hash without the '#' const targetId = window.location.hash.substring(1); const targetElement = document.getElementById(targetId); if (targetId) { var target = jQuery("#" + targetId); var targetOffset = target.offset().top; var targetPosition = target.offset().top - 100; //console.log("12 - targetPosition:" + targetOffset); jQuery("html, body").scrollTop(parseFloat(targetOffset)); } }*/ }; document.addEventListener("DOMContentLoaded", function () { // Check if there is a hash in the URL if (window.location.hash) { // Extract the hash without the '#' const targetId = window.location.hash.substring(1); // Find the target element const targetElement = document.getElementById(targetId); const breadcrumbs = document.getElementById("breadcrumbs"); if (targetElement) { let url = window.location.href; // Check if the URL contains the 'readmore' parameter if (url.includes("readmore")) { // Remove the hash from the URL var target = jQuery("#" + targetId); var targetOffset = target.offset().top; var targetPosition = target.offset().top - 100; console.log("34 - targetPosition:" + targetPosition); //jQuery("html, body").scrollTop(targetPosition); let newUrl = url.split("#")[0]; history.replaceState( null, null, window.location.pathname + window.location.search ); } } /*29052024-2204 changes start*/ /* if (window.location.hash) { // Extract the hash without the '#' const targetId = window.location.hash.substring(1); const targetElement = document.getElementById(targetId); if (targetId) { var target = jQuery("#" + targetId); var targetOffset = target.offset().top; var targetPosition = target.offset().top - 150; console.log("54 -targetPosition:" + targetPosition); jQuery("html, body").scrollTop(parseFloat(targetPosition)); } }*/ /* changes end*/ } }); jQuery(function ($) { function scrollToHash() { if (window.location.hash) { const targetId = window.location.hash.substring(1); const $target = $("#" + targetId); if ($target.length) { // Use setTimeout to ensure proper element positioning setTimeout(() => { const targetPosition = $target.offset().top - 150; console.log("Scrolling to:", targetPosition); $("html, body").scrollTop(targetPosition); }, 100); } } } // Run after DOM is ready scrollToHash(); // Run again on window load (ensuring images, fonts, and CSS are fully rendered) $(window).on("load", function () { scrollToHash(); }); // Handle cases where WP Rocket delays JavaScript execution document.addEventListener("DOMContentLoaded", scrollToHash); setTimeout(scrollToHash, 500); });